package com.lvcoding.spring5.annotation3x.config;

import com.lvcoding.spring5.annotation3x.injection.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @Description 描述
 * @Date 2020-07-22 3:13 下午
 * @Author wuyanshen
 */
@Configuration
@PropertySource("classpath:/init.properties")
public class AppConfig1 {

    @Value("${id}")
    private Integer id;
    @Value("${name}")
    private String  name;


    @Bean
    public UserDao userDao(){
        return new UserDaoImpl();
    }

    //@Bean
    //public UserService userService(UserDao userDao){
    //    UserServiceImpl userService = new UserServiceImpl();
    //    userService.setUserDao(userDao);
    //    return userService;
    //}

    //简化写法
    @Bean
    public UserService userService(){
        UserServiceImpl userService = new UserServiceImpl();
        //userService.setUserDao(userDao());
        return userService;
    }

    @Bean
    public User user(){
        User user = new User();
        user.setId(id);
        user.setName(name);
        return user;
    }
}
